<template>
<div>
    <div class="registerBackground">
        <img :src="imgSrc" width="100%" height="100%" alt="" />
    </div>
  <div class="Register">
    <div>
      <el-form
          v-loading="loading"
          element-loading-text="loading..."
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.8)"
          :rules="rules"
          ref="loginForm"
          :model="loginForm"
          class="registerContainer"
      >
        <h1 class="registerTitle">Register</h1>

        <el-form-item prop="username">
          <el-input
              type="text"
              auto-complete="false"
              v-model="loginForm.username"
              placeholder="username"
          ></el-input>
        </el-form-item>

        <el-form-item prop="email">
          <el-input
              type="text"
              auto-complete="false"
              v-model="loginForm.email"
              placeholder="email"
          ></el-input>
        </el-form-item>

        <el-form-item prop="password">
          <el-input
              type="password"
              auto-complete="false"
              v-model="loginForm.password"
              placeholder="password"
          ></el-input>
        </el-form-item>

        <el-form-item prop="cpassword">
          <el-input
              type="cpassword"
              auto-complete="false"
              v-model="loginForm.cpassword"
              placeholder="Confirm password"
          ></el-input>
        </el-form-item>

        <el-form-item prop="code">
          <el-input
              size="normal"
              type="text"
              auto-complete="false"
              v-model="loginForm.code"
              placeholder="Click on"
              style="width: 250px; margin-right: 5px"
          ></el-input>
          <img :src="captchaUrl" @click="updateCaptcha" />
        </el-form-item>

        <el-button type="info" plain style=" width: 100%" @click="submitLogin" @keyup.enter="submitLogin"
        >Register</el-button
        >

      </el-form>
    </div>
    <vue-particles
        color="#fff"
        :particleOpacity="0.7"
        :particlesNumber="60"
        shapeType="circle"
        :particleSize="4"
        linesColor="#fff"
        :linesWidth="1"
        :lineLinked="true"
        :lineOpacity="0.4"
        :linesDistance="150"
        :moveSpeed="2"
        :hoverEffect="true"
        hoverMode="grab"
        :clickEffect="true"
        clickMode="push"
        class="lizi"
        style="height: 100%"
    ></vue-particles>
  </div>
    </div>
</template>


<script>


export default {
  name: "Login",
  data() {
    return {
      imgSrc:require('../img/R-C.jpg'),
      captchaUrl: "/captcha?time=" + new Date(),
      loginForm: {
        username: "",
        password: "",
        email: "",
        agreed: false,
        cpassword:"",
        code: "",
      },
      loading: false,
      checked: true,
      rules: {
        agreed: [{
          validator: (rule, value, callback) => {
            // console.log('value:' + value)
            if (value !== true) {
              callback(new Error('请确认同意注册协议'))
            } else {
              callback()
            }
          },
          trigger: 'blur'
        }],
        username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
        email: [{ required: true, message: "请输入邮箱", trigger: "blur" }],
        code: [{ required: true, message: "请输入验证码", trigger: "blur" }],
        cpassword: [{
          required: true,
          message: '确认密码',
          trigger: 'blur'
        }, {
          validator: (rule, value, callback) => {
            if (value === '') {
              callback(new Error('请再次输入密码'))
            } else if (value !== this.loginForm.password) {
              callback(new Error('两次输入密码不一致'))
            } else {
              callback()
            }
          },
          trigger: 'blur'
        }]
      },
    };
  },
  methods: {
    updateCaptcha() {
      this.captchaUrl = "/captcha?time=" + new Date();
    },
    submitLogin() {
      this.loading = true;
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.postRequest('/register',this.loginForm).then(resp=>{
            if(resp){
              this.loading = false;
              this.$router.replace('/Login');
            }
          })
          // this.loading = true;
          // this.postRequest("/login", this.loginForm).then((resp) => {
          //   if (resp=="登录成功") {
          //     this.loading = false;
          //     this.$message.success(resp);
          //     //跳转首页
          //     //this.$router.replace('/HomePage')
          //     //跳转登录页面后，登录直接进入指定页面
          //     let path = this.$route.query.redirect;
          //     this.$router.replace((path== '/'||path==undefined)?'/HomePage':path);
          //   } else {
          //     this.loading = false;
          //     this.$message.error(resp);
          //     this.updateCaptcha();
          //   }
          // });
        } else {
          this.$message.error("请输入全部信息！");
          return false;
        }
      });
    },
  },
};
</script>


<style >
    .el-textarea__inner,.el-input__inner{
        background-color: transparent !important;;
    }

.Register {
  background-color: antiquewhite;
  background-repeat: no-repeat;
  background-size: cover;
  height: auto;
}
.registerBackground {
    width:100%;
    height:100%;  /**宽高100%是为了图片铺满屏幕 **/
    z-index:-1;
    position: absolute;
}
.registerContainer {
  /*border-radius: 10px;*/
  /*background-clip: padding-box;*/
  /*margin: 0px auto;*/
  /*transform: translateY(50%);*/
  /*width: 358px;*/
  /*padding: 15px 35px 15px 35px;*/
  /*background: #3594e7;*/
  /*border: 1px solid #7e7a7f;*/
  /*box-shadow: 0 0 25px #4a4b52;*/
    position:absolute;
    /*定位方式绝对定位absolute*/
    top:50%;
    left:80%;
    /*顶和高同时设置50%实现的是同时水平垂直居中效果*/
    transform:translate(-50%,-50%);
    /*实现块元素百分比下居中*/
    width:300px;
    padding:50px;
    background: rgba(0,0,0,.1);
    /*背景颜色为黑色，透明度为0.8*/
    box-sizing:border-box;
    /*box-sizing设置盒子模型的解析模式为怪异盒模型，
    将border和padding划归到width范围内*/
    box-shadow: 0px 15px 25px rgba(0,0,0,.5);
    /*边框阴影  水平阴影0 垂直阴影15px 模糊25px 颜色黑色透明度0.5*/
    border-radius:15px;
    /*边框圆角，四个角均为15px*/
}

.registerTitle {
  margin: 0px auto 40px auto;
  text-align: center;
  color: #88888b;
}
.el-form-item__content{
  display: flex;
  align-items: center;
}

</style>